package com.youlu.campus.web.community.controller;

import com.youlu.campus.entity.VO.req.QaCommitCommand;
import com.youlu.campus.service.aomen.AoMenService;
import com.youlu.campus.service.qa.ActivityH5ContestQaService;
import com.youlu.campus.service.qa.UserQaInfoService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 老版本H5竞赛控制器
 */
@RestController
public class ActivityH5ContestController {

    @Autowired
    private ActivityH5ContestQaService activityH5ContestQaService;

    @Autowired
    private UserQaInfoService userQaInfoService;

    @Autowired
    private AoMenService aoMenService;

    /**
     * 老版本H5竞赛答题信息
     * @param activityId 活动ID
     * @param contestQaType 答题竞赛类型 1、非专业竞赛答题 2、专业组竞赛答题
     * @return
     */
    @GetMapping("/mini-app/h5-contest/user-qa/list")
    public  QResult h5QaContestInfo(@RequestParam("activityId") String activityId,
                                    @RequestParam(defaultValue = "1")Integer contestQaType){
     return QResult.success(activityH5ContestQaService.getH5QaContestInfo(RequestContext.getCurUser(),activityId,contestQaType));
    }


    /**
     * 答题提交-老版H5-专业组竞赛和非专业组竞赛
     *
     * @param
     * @return
     */
    @PostMapping("/mini-app/h5-contest/user-qa/commit")
    public QResult qaCommit(@RequestBody @Validated QaCommitCommand commitCommand, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return QResult.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        commitCommand.setCurrentUser(RequestContext.getCurUser());
        //H5-老版本提交题库
        commitCommand.setType(4);
        return QResult.success(userQaInfoService.doQaCommit(commitCommand));
    }

    /**
     * 获取澳门活动用户链接
     * @param activityId
     * @return
     */
    @GetMapping("/mini-app/aomen/qa-link")
    public  QResult userQaAoMenUrl(@RequestParam("activityId") String activityId){
        return QResult.success(aoMenService.getRedirectUriContest(RequestContext.getUserId(),activityId));
    }





}
